#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdbool.h>
#include <unistd.h>
#include <signal.h>
#include <signal.h>
#include "tools.h"
#include "msg.h"

pid_t chl_pid[6];

void sigint(int sig)
{
	destory_msg();

	for(int i=0; i<1; i++)
	{
		kill(chl_pid[i], SIGKILL);
	}
	raise(SIGKILL);
}

int main(void)
{
	signal(SIGINT, sigint);

	init_msg(110);
	
	chl_pid[0] = vfork();
	if(0 == chl_pid[0])
	{
		execl("open", "open", NULL);
	}

	chl_pid[1] = vfork();
	if(0 == chl_pid[1])
	{
		execl("close", "close", NULL);
	}

	chl_pid[2] = vfork();
	if(0 == chl_pid[2])
	{
		execl("enter", "enter", NULL);
	}

	chl_pid[3] = vfork();
	if(0 == chl_pid[3])
	{
		execl("unlock", "unlock", NULL);
	}

	chl_pid[4] = vfork();
	if(0 == chl_pid[4])
	{
		execl("transfer", "transfer", NULL);
	}
	
	chl_pid[5] = vfork();
	if(0 == chl_pid[5])
	{
		execl("stqc", "stqc", NULL);
	}

	for(;;)pause();
}
